#include <sys/select.h>
#include <poll.h>
#include <unistd.h>
#include <cstring>
#include <iostream>

int main()
{
   struct pollfd pfd;
   bzero(&pfd, sizeof(pfd));
   pfd.fd = 0;
   pfd.events = POLLIN;
   char buffer[64]; buffer[0] = 0;
   while (true)
   {
      // pfd.revents = 0;
      int ret = poll(&pfd, 1, 3000);
      if (ret < 0) {
	 // err
      }
      else if (ret == 0) {
	 // timeout
	 std::cout << "timeout..." << std::endl;
      }
      else {
	 if (pfd.revents | POLLIN) {
	    // ready
	    std::cout << "ready..." << std::endl;
	    int n = read(pfd.fd, buffer, 64);
	    buffer[n] = 0;
	    std::cout << "input: " << buffer;
	 }
	 else {
	    // invalid fd
	 }
      }
   }
   return 0;
}
